package com.zillion.employee.service.impl;

import com.zillion.common.core.redis.RedisCache;
import com.zillion.employee.domain.PersonApply;
import com.zillion.employee.mapper.PersonApplyMapper;
import com.zillion.employee.service.IPersonApplyService;
import com.zillion.health.domain.HealthPersonInfo;
import com.zillion.health.domain.vo.UISelectDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class PersonApplyServiceImpl implements IPersonApplyService {

    @Autowired
    private PersonApplyMapper personApplyMapper;

    @Autowired
    private RedisCache redisCache; // 注入 RedisCache

    /*名族列表*/
    private static final String ETHNIC_KEY = "ethnic:list";
    /*园区列表*/
    private static final String PARK_ID_KEY = "parkId:list";
    /*工种列表*/
    private static final String JOB_TYPES_KEY = "jobTypes:list";

    /**
     * 新增个人申报信息
     * @param healthPersonInfo 个人申报信息
     * @return 处理行数
     */
    @Override
    public int insertHealthPersonApply(HealthPersonInfo healthPersonInfo) {
        return personApplyMapper.insertHealthPersonApply(healthPersonInfo);
    }

    /**
     * 查询民族列表
     * @return 民族列表
     */
    @Override
    public List<UISelectDataVo> listEthnic() {
        // 从 Redis 获取数据
        List<UISelectDataVo> ethnicList = redisCache.getCacheList(ETHNIC_KEY);
        if (ethnicList == null || ethnicList.isEmpty()) {
            // 如果 Redis 中没有数据，则从数据库获取
            ethnicList = personApplyMapper.listEthnic();
            if (ethnicList != null && !ethnicList.isEmpty()) {
                // 将数据写入 Redis
                redisCache.setCacheList(ETHNIC_KEY, ethnicList);
            }
        }
        return ethnicList;
    }

    /**
     * 查询园区列表
     * @return 园区列表
     */
    @Override
    public List<UISelectDataVo> listParkId() {
        // 从 Redis 获取数据
        List<UISelectDataVo> parkIdList = redisCache.getCacheList(PARK_ID_KEY);
        if (parkIdList == null || parkIdList.isEmpty()) {
            // 如果 Redis 中没有数据，则从数据库获取
            parkIdList = personApplyMapper.listParkId();
            if (parkIdList != null && !parkIdList.isEmpty()) {
                // 将数据写入 Redis
                redisCache.setCacheList(PARK_ID_KEY, parkIdList);
            }
        }
        return parkIdList;
    }

    /**
     * 查询工种列表
     * @return 工种列表
     */
    @Override
    public List<UISelectDataVo> listJobTypes() {
        // 从 Redis 获取数据
        List<UISelectDataVo> jobTypeList = redisCache.getCacheList(JOB_TYPES_KEY);
        if (jobTypeList == null || jobTypeList.isEmpty()) {
            // 如果 Redis 中没有数据，则从数据库获取
            jobTypeList = personApplyMapper.listJobTypes();
            if (jobTypeList != null && !jobTypeList.isEmpty()) {
                // 将数据写入 Redis
                redisCache.setCacheList(JOB_TYPES_KEY, jobTypeList);
            }
        }
        return jobTypeList;
    }

    @Override
    public List<PersonApply> selectPersonApplyList(PersonApply personApply) {
        return Collections.emptyList();
    }

    @Override
    public PersonApply selectPersonApplyById(Long personApplyId) {
        return null;
    }

    @Override
    public int selectNormalChildrenPersonApplyById(Long personApplyId) {
        return 0;
    }

    @Override
    public boolean hasChildByPersonApplyId(Long personApplyId) {
        return false;
    }

    @Override
    public boolean checkPersonApplyExistUser(Long personApplyId) {
        return false;
    }

    @Override
    public boolean checkPersonApplyNameUnique(PersonApply personApply) {
        return false;
    }

    @Override
    public int updatePersonApply(PersonApply personApply) {
        return 0;
    }

    @Override
    public int deletePersonApplyById(Long personApplyId) {
        return 0;
    }

}
